import * as Cesium from 'cesium';
import point_img from '../assets/point.png'
export class MapBusinessOperations {
  constructor(cesiumManager) {
    this.cesiumManager = cesiumManager;
    this.drawHandler = null;
    this.activeEntity = null;
    this.tempEntities = [];
    this.primitiveCollection = null;
    this.entityCollections = new Map();
    // 存储聚合点数据
    this.clusterData = [];
    this.clusterEntities = [];
    // 添加缓存机制以提高性能
    this.clusterCache = new Map();
    this.lastCameraPosition = null;
    this.lastCameraHeight = null;
    // 添加防抖控制变量
    this.clusterUpdateTimeout = null;
    this.isUpdatingClusters = false;
  }

  // 添加点要素
  addPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        const entity = viewer.entities.add({
          position: cartesian,
          point: {
            pixelSize: 10,
            color: Cesium.Color.RED,
            outlineColor: Cesium.Color.WHITE,
            outlineWidth: 2
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加图标点
  addBillboardPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: point_img, // 需要提供图标文件
            width: 32,
            height: 32
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加带标签的图标点
  addLabeledBillboardPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: '/images/location.png',
            width: 32,
            height: 32
          },
          label: {
            text: '标注点',
            font: '14px sans-serif',
            fillColor: Cesium.Color.WHITE,
            outlineColor: Cesium.Color.BLACK,
            outlineWidth: 2,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            pixelOffset: new Cesium.Cartesian2(0, -32)
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加带水波纹效果的图标点
  addRipplePoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 主图标点
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: '/images/location.png',
            width: 32,
            height: 32
          }
        });
        this.tempEntities.push(entity);
        
        // 添加水波纹效果（通过多个扩散圆实现）
        for (let i = 0; i < 3; i++) {
          setTimeout(() => {
            const ripple = viewer.entities.add({
              position: cartesian,
              ellipse: {
                semiMajorAxis: new Cesium.CallbackProperty(() => 10 + (Date.now() % 5000) / 100, false),
                semiMinorAxis: new Cesium.CallbackProperty(() => 10 + (Date.now() % 5000) / 100, false),
                material: Cesium.Color.BLUE.withAlpha(0.5 - (Date.now() % 5000) / 10000),
                outline: true,
                outlineColor: Cesium.Color.BLUE,
                outlineWidth: 1
              }
            });
            this.tempEntities.push(ripple);
            
            // 一段时间后移除波纹
            setTimeout(() => {
              viewer.entities.remove(ripple);
              const index = this.tempEntities.indexOf(ripple);
              if (index > -1) {
                this.tempEntities.splice(index, 1);
              }
            }, 5000);
          }, i * 1000);
        }
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加带状态的图标点
  addStatusPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 随机选择一个状态
        const statuses = ['online', 'offline', 'warning'];
        const status = statuses[Math.floor(Math.random() * statuses.length)];
        
        let color, image;
        switch (status) {
          case 'online':
            color = Cesium.Color.GREEN;
            image = '/images/online.png';
            break;
          case 'offline':
            color = Cesium.Color.RED;
            image = '/images/offline.png';
            break;
          case 'warning':
            color = Cesium.Color.YELLOW;
            image = '/images/warning.png';
            break;
          default:
            color = Cesium.Color.BLUE;
            image = '/images/location.png';
        }
        
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: image,
            width: 32,
            height: 32
          },
          label: {
            text: status,
            font: '12px sans-serif',
            fillColor: color,
            outlineColor: Cesium.Color.BLACK,
            outlineWidth: 2,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            pixelOffset: new Cesium.Cartesian2(0, -32)
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加文本点
  addTextPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        const entity = viewer.entities.add({
          position: cartesian,
          label: {
            text: '文本点',
            font: '16px sans-serif',
            fillColor: Cesium.Color.CYAN,
            outlineColor: Cesium.Color.BLACK,
            outlineWidth: 2,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            verticalOrigin: Cesium.VerticalOrigin.CENTER,
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加HTML点
  addHtmlPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 创建一个自定义HTML元素并转换为画布
        const canvas = document.createElement('canvas');
        canvas.width = 100;
        canvas.height = 50;
        const ctx = canvas.getContext('2d');
        
        // 绘制简单的HTML样式内容
        ctx.fillStyle = 'rgba(0, 150, 255, 0.8)';
        ctx.fillRect(0, 0, 100, 50);
        ctx.fillStyle = 'white';
        ctx.font = '14px Arial';
        ctx.fillText('HTML点', 25, 30);
        
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: canvas.toDataURL(),
            width: 100,
            height: 50
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加GIF点（简单模拟）
  addGifPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 模拟GIF动画，通过切换不同的图像
        const images = [
          '/images/gif1.png',
          '/images/gif2.png',
          '/images/gif3.png'
        ];
        
        let currentIndex = 0;
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: new Cesium.CallbackProperty(() => {
              return images[currentIndex];
            }, false),
            width: 32,
            height: 32
          }
        });
        this.tempEntities.push(entity);
        
        // 模拟动画效果
        const interval = setInterval(() => {
          currentIndex = (currentIndex + 1) % images.length;
        }, 500);
        
        // 保存定时器引用，以便后续清理
        entity._animationInterval = interval;
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加带动画的GIF点
  addAnimatedGifPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 创建一个带动画效果的点
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: '/images/animated.gif', // 需要实际的GIF文件
            width: 48,
            height: 48
          }
        });
        this.tempEntities.push(entity);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加GIF聚合点
  addGifAggregatedPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 以长沙为中心生成聚合点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 创建聚合点集合
    const positions = [];
    for (let i = 0; i < 50; i++) {
      // 在中心点附近随机生成经纬度
      const lon = centerLon + (Math.random() - 0.5) * 1.0;
      const lat = centerLat + (Math.random() - 0.5) * 1.0;
      positions.push(Cesium.Cartesian3.fromDegrees(lon, lat));
    }
    
    // 创建聚合点实体
    const entity = viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(centerLon, centerLat),
      billboard: {
        image: '/images/cluster.gif', // 聚合点GIF图标
        width: 64,
        height: 64
      },
      label: {
        text: '50',
        font: '16px sans-serif',
        fillColor: Cesium.Color.WHITE,
        outlineColor: Cesium.Color.BLACK,
        outlineWidth: 2,
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        verticalOrigin: Cesium.VerticalOrigin.CENTER,
        pixelOffset: new Cesium.Cartesian2(20, 0)
      }
    });
    this.tempEntities.push(entity);
    
    console.log('添加GIF聚合点，包含50个子点');
  }

  // 添加扩散圆
  addDiffuseCircle() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 创建扩散圆效果
        const startTime = Date.now();
        const maxRadius = 100000; // 最大半径(米)
        
        const entity = viewer.entities.add({
          position: cartesian,
          ellipse: {
            semiMajorAxis: new Cesium.CallbackProperty(() => {
              const elapsed = Date.now() - startTime;
              return Math.min(maxRadius, elapsed / 50);
            }, false),
            semiMinorAxis: new Cesium.CallbackProperty(() => {
              const elapsed = Date.now() - startTime;
              return Math.min(maxRadius, elapsed / 50);
            }, false),
            material: new Cesium.ColorMaterialProperty(
              new Cesium.CallbackProperty(() => {
                const elapsed = Date.now() - startTime;
                const alpha = Math.max(0, 0.8 - elapsed / 5000);
                return Cesium.Color.BLUE.withAlpha(alpha);
              }, false)
            )
          }
        });
        this.tempEntities.push(entity);
        
        // 5秒后移除扩散圆
        setTimeout(() => {
          viewer.entities.remove(entity);
          const index = this.tempEntities.indexOf(entity);
          if (index > -1) {
            this.tempEntities.splice(index, 1);
          }
        }, 5000);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加带扩散圆的图标点
  addBillboardDiffuseCircle() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 添加图标点
        const entity = viewer.entities.add({
          position: cartesian,
          billboard: {
            image: '/images/location.png',
            width: 32,
            height: 32
          }
        });
        this.tempEntities.push(entity);
        
        // 创建扩散圆效果
        const startTime = Date.now();
        const maxRadius = 50000; // 最大半径(米)
        
        const circleEntity = viewer.entities.add({
          position: cartesian,
          ellipse: {
            semiMajorAxis: new Cesium.CallbackProperty(() => {
              const elapsed = Date.now() - startTime;
              return Math.min(maxRadius, elapsed / 100);
            }, false),
            semiMinorAxis: new Cesium.CallbackProperty(() => {
              const elapsed = Date.now() - startTime;
              return Math.min(maxRadius, elapsed / 100);
            }, false),
            material: new Cesium.ColorMaterialProperty(
              new Cesium.CallbackProperty(() => {
                const elapsed = Date.now() - startTime;
                const alpha = Math.max(0, 0.5 - elapsed / 10000);
                return Cesium.Color.CYAN.withAlpha(alpha);
              }, false)
            )
          }
        });
        this.tempEntities.push(circleEntity);
        
        // 10秒后移除扩散圆
        setTimeout(() => {
          viewer.entities.remove(circleEntity);
          const index = this.tempEntities.indexOf(circleEntity);
          if (index > -1) {
            this.tempEntities.splice(index, 1);
          }
        }, 10000);
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加聚合点
  addAggregatedPoint() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 以长沙为中心生成聚合点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 创建聚合点集合
    const positions = [];
    for (let i = 0; i < 30; i++) {
      // 在中心点附近随机生成经纬度
      const lon = centerLon + (Math.random() - 0.5) * 0.5;
      const lat = centerLat + (Math.random() - 0.5) * 0.5;
      positions.push(Cesium.Cartesian3.fromDegrees(lon, lat));
    }
    
    // 创建聚合点实体
    const entity = viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(centerLon, centerLat),
      point: {
        pixelSize: 30,
        color: Cesium.Color.ORANGE.withAlpha(0.8),
        outlineColor: Cesium.Color.WHITE,
        outlineWidth: 2
      },
      label: {
        text: '30',
        font: '16px sans-serif',
        fillColor: Cesium.Color.WHITE,
        outlineColor: Cesium.Color.BLACK,
        outlineWidth: 2,
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        verticalOrigin: Cesium.VerticalOrigin.CENTER,
        pixelOffset: new Cesium.Cartesian2(20, 0)
      }
    });
    this.tempEntities.push(entity);
    
    console.log('添加聚合点，包含30个子点');
  }

  // 添加聚合图标点1
  addAggregatedBillboard1() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 以长沙为中心生成聚合点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 创建聚合点集合
    const positions = [];
    for (let i = 0; i < 20; i++) {
      // 在中心点附近随机生成经纬度
      const lon = centerLon + (Math.random() - 0.5) * 0.3;
      const lat = centerLat + (Math.random() - 0.5) * 0.3;
      positions.push(Cesium.Cartesian3.fromDegrees(lon, lat));
    }
    
    // 创建聚合点实体
    const entity = viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(centerLon, centerLat),
      billboard: {
        image: '/images/cluster1.png',
        width: 48,
        height: 48
      },
      label: {
        text: '20',
        font: '14px sans-serif',
        fillColor: Cesium.Color.WHITE,
        outlineColor: Cesium.Color.BLACK,
        outlineWidth: 2,
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        verticalOrigin: Cesium.VerticalOrigin.CENTER,
        pixelOffset: new Cesium.Cartesian2(25, 0)
      }
    });
    this.tempEntities.push(entity);
    
    console.log('添加聚合图标点1，包含20个子点');
  }

  // 添加聚合图标点2
  addAggregatedBillboard2() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 以长沙为中心生成聚合点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 创建聚合点集合
    const positions = [];
    for (let i = 0; i < 45; i++) {
      // 在中心点附近随机生成经纬度
      const lon = centerLon + (Math.random() - 0.5) * 0.7;
      const lat = centerLat + (Math.random() - 0.5) * 0.7;
      positions.push(Cesium.Cartesian3.fromDegrees(lon, lat));
    }
    
    // 创建聚合点实体
    const entity = viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(centerLon, centerLat),
      billboard: {
        image: '/images/cluster2.png',
        width: 56,
        height: 56
      },
      label: {
        text: '45',
        font: '16px sans-serif',
        fillColor: Cesium.Color.WHITE,
        outlineColor: Cesium.Color.BLACK,
        outlineWidth: 2,
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        verticalOrigin: Cesium.VerticalOrigin.CENTER,
        pixelOffset: new Cesium.Cartesian2(30, 0)
      }
    });
    this.tempEntities.push(entity);
    
    console.log('添加聚合图标点2，包含45个子点');
  }

  // 添加聚合图标点3
  addAggregatedBillboard3() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 以长沙为中心生成聚合点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 创建聚合点集合
    const positions = [];
    for (let i = 0; i < 75; i++) {
      // 在中心点附近随机生成经纬度
      const lon = centerLon + (Math.random() - 0.5) * 1.0;
      const lat = centerLat + (Math.random() - 0.5) * 1.0;
      positions.push(Cesium.Cartesian3.fromDegrees(lon, lat));
    }
    
    // 创建聚合点实体
    const entity = viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(centerLon, centerLat),
      billboard: {
        image: '/images/cluster3.png',
        width: 64,
        height: 64
      },
      label: {
        text: '75',
        font: '18px sans-serif',
        fillColor: Cesium.Color.WHITE,
        outlineColor: Cesium.Color.BLACK,
        outlineWidth: 2,
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        verticalOrigin: Cesium.VerticalOrigin.CENTER,
        pixelOffset: new Cesium.Cartesian2(35, 0)
      }
    });
    this.tempEntities.push(entity);
    
    console.log('添加聚合图标点3，包含75个子点');
  }

  // 添加行政聚合
  addAdministrativeAggregation() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 模拟几个城市的行政聚合点
    const cities = [
      { name: '长沙', lon: 112.98, lat: 28.19, count: 120 },
      { name: '株洲', lon: 113.15, lat: 27.83, count: 85 },
      { name: '湘潭', lon: 112.91, lat: 27.87, count: 65 }
    ];
    
    cities.forEach(city => {
      const entity = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(city.lon, city.lat),
        billboard: {
          image: '/images/admin_cluster.png',
          width: 50,
          height: 50
        },
        label: {
          text: `${city.name}\n${city.count}`,
          font: '14px sans-serif',
          fillColor: Cesium.Color.WHITE,
          outlineColor: Cesium.Color.BLACK,
          outlineWidth: 2,
          style: Cesium.LabelStyle.FILL_AND_OUTLINE,
          verticalOrigin: Cesium.VerticalOrigin.CENTER,
          pixelOffset: new Cesium.Cartesian2(30, 0)
        }
      });
      this.tempEntities.push(entity);
    });
    
    console.log('添加行政聚合点');
  }

  // 添加聚合点单击事件
  addClickAggregation() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 创建一个聚合点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    const entity = viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(centerLon, centerLat),
      billboard: {
        image: '/images/cluster_click.png',
        width: 48,
        height: 48
      },
      label: {
        text: '点击展开',
        font: '14px sans-serif',
        fillColor: Cesium.Color.WHITE,
        outlineColor: Cesium.Color.BLACK,
        outlineWidth: 2,
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        verticalOrigin: Cesium.VerticalOrigin.CENTER,
        pixelOffset: new Cesium.Cartesian2(30, 0)
      },
      properties: {
        isCluster: true,
        count: 25
      }
    });
    this.tempEntities.push(entity);
    
    // 添加点击事件处理器
    const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handler.setInputAction((click) => {
      const pickedObject = viewer.scene.pick(click.position);
      if (pickedObject && pickedObject.id && pickedObject.id.properties && 
          pickedObject.id.properties.isCluster) {
        console.log('点击了聚合点，展开子点');
        
        // 移除聚合点
        viewer.entities.remove(pickedObject.id);
        const index = this.tempEntities.indexOf(pickedObject.id);
        if (index > -1) {
          this.tempEntities.splice(index, 1);
        }
        
        // 添加子点
        const count = pickedObject.id.properties.count.getValue();
        for (let i = 0; i < count; i++) {
          const lon = centerLon + (Math.random() - 0.5) * 0.1;
          const lat = centerLat + (Math.random() - 0.5) * 0.1;
          
          const childEntity = viewer.entities.add({
            position: Cesium.Cartesian3.fromDegrees(lon, lat),
            point: {
              pixelSize: 8,
              color: Cesium.Color.fromRandom({alpha: 0.8}),
              outlineColor: Cesium.Color.WHITE,
              outlineWidth: 1
            }
          });
          this.tempEntities.push(childEntity);
        }
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
    console.log('添加带点击事件的聚合点');
  }

  // 新增创建聚合点图标的方法
  createClusterIcon(count) {
    let size, color;
    
    // 根据点数量确定图标大小和颜色
    if (count < 10) {
      size = 32;
      color = '#00ff00'; // 绿色
    } else if (count < 50) {
      size = 48;
      color = '#ffaa00'; // 橙色
    } else {
      size = 64;
      color = '#ff0000'; // 红色
    }
    
    // 创建Canvas绘制图标
    const canvas = document.createElement('canvas');
    canvas.width = size;
    canvas.height = size;
    const context = canvas.getContext('2d');
    
    // 绘制圆形背景
    context.beginPath();
    context.arc(size/2, size/2, size/2 - 2, 0, 2 * Math.PI);
    context.fillStyle = color;
    context.fill();
    context.strokeStyle = '#ffffff';
    context.lineWidth = 2;
    context.stroke();
    
    // 绘制数字
    context.font = `${Math.max(12, size/3)}px Arial`;
    context.textAlign = 'center';
    context.textBaseline = 'middle';
    context.fillStyle = '#ffffff';
    context.fillText(count.toString(), size/2, size/2);
    
    // 返回图标URL和尺寸信息的对象
    return {
      url: canvas.toDataURL(),
      size: size
    };
  }

  // 新增功能：撒点加聚合结合 - 随机生成数百个点并自动聚合
  addScatterAndClusterPoints() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 以长沙为中心生成随机点
    const centerLon = 112.98;
    const centerLat = 28.19;
    const pointCount = 1000; // 生成300个点
    
    // 创建点集合用于聚合
    const points = [];
    for (let i = 0; i < pointCount; i++) {
      // 在中心点附近随机生成经纬度 (-0.2到0.2度的偏移)
      const lon = centerLon + (Math.random() - 0.5) * 0.4;
      const lat = centerLat + (Math.random() - 0.5) * 0.4;
      points.push({ lon, lat });
    }
    
    // 保存点数据用于后续聚合
    this.clusterData = points;
    
    // 初始聚合显示
    this.updateClusters();
    
    // 监听地图层级变化事件
    this.clusterChangeListener = this.updateClusters.bind(this);
    viewer.camera.changed.addEventListener(this.clusterChangeListener);
    
    console.log(`添加了 ${pointCount} 个随机点`);
  }

  // 更新聚合点显示
  updateClusters() {
    // 防抖机制：延迟执行更新，避免频繁触发
    if (this.clusterUpdateTimeout) {
      clearTimeout(this.clusterUpdateTimeout);
    }

    this.clusterUpdateTimeout = setTimeout(() => {
      this._performClusterUpdate();
    }, 150); // 保持原来的150ms防抖延迟
  }

  // 实际执行聚合点更新的函数
  _performClusterUpdate() {
    if (!this.cesiumManager || !this.cesiumManager.viewer || this.isUpdatingClusters) return;
    
    this.isUpdatingClusters = true;
    
    const viewer = this.cesiumManager.viewer;
    const camera = viewer.camera;
    
    // 获取当前地图层级（高度）
    const height = camera.positionCartographic.height;
    
    // 添加防抖机制，避免频繁更新
    if (this.lastCameraHeight !== null) {
      const heightDiff = Math.abs(height - this.lastCameraHeight);
      // 如果高度变化不大，则不更新
      // 修改判断条件，使触发更灵敏，并考虑相对变化
      if (heightDiff < 1000 && (height > 50000 || heightDiff / height < 0.02)) {
        this.isUpdatingClusters = false;
        return;
      }
    }
    
    this.lastCameraHeight = height;
    
    // 根据地图层级决定是否展开点
    if (height < 50000 && this.clusterData.length > 0) {
      // 当高度小于50000米时，显示所有原始点
      // 先创建新的点实体
      const newClusterEntities = [];
      
      this.clusterData.forEach(point => {
        const pointEntity = viewer.entities.add({
          position: Cesium.Cartesian3.fromDegrees(point.lon, point.lat),
          point: {
            pixelSize: 6,
            color: Cesium.Color.fromRandom({alpha: 0.8}),
            outlineColor: Cesium.Color.WHITE,
            outlineWidth: 1
          }
        });
        newClusterEntities.push(pointEntity);
      });
      
      // 直接替换旧实体，不使用延迟
      this.clusterEntities.forEach(entity => {
        viewer.entities.remove(entity);
      });
      this.clusterEntities = newClusterEntities;
    } else if (this.clusterData.length > 0) {
      // 使用网格聚合算法
      const gridSize = this.getGridSizeByHeight(height);
      const clusters = new Map();
      
      // 将点分配到网格中
      this.clusterData.forEach(point => {
        const gridX = Math.floor(point.lon / gridSize);
        const gridY = Math.floor(point.lat / gridSize);
        const key = `${gridX},${gridY}`;
        
        if (!clusters.has(key)) {
          clusters.set(key, {
            points: [],
            centerLon: 0,
            centerLat: 0
          });
        }
        
        clusters.get(key).points.push(point);
      });
      
      // 计算每个簇的中心点和点数量
      clusters.forEach(cluster => {
        cluster.centerLon = cluster.points.reduce((sum, p) => sum + p.lon, 0) / cluster.points.length;
        cluster.centerLat = cluster.points.reduce((sum, p) => sum + p.lat, 0) / cluster.points.length;
      });
      
      // 创建聚合点
      const newClusterEntities = [];
      clusters.forEach((cluster, key) => {
        const count = cluster.points.length;
        
        // 使用Canvas绘制的图标替代图片
        const iconInfo = this.createClusterIcon(count);
        const imageUrl = iconInfo.url;
        const size = iconInfo.size; // 直接使用返回的尺寸信息
        
        const clusterEntity = viewer.entities.add({
          position: Cesium.Cartesian3.fromDegrees(cluster.centerLon, cluster.centerLat),
          billboard: {
            image: imageUrl,
            width: size,
            height: size
          },
          label: {
            text: count.toString(),
            font: '14px sans-serif',
            fillColor: Cesium.Color.WHITE,
            outlineColor: Cesium.Color.BLACK,
            outlineWidth: 2,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            verticalOrigin: Cesium.VerticalOrigin.CENTER,
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            pixelOffset: new Cesium.Cartesian2(size/4, -size/4)
          },
          properties: {
            isCluster: true,
            points: cluster.points
          }
        });
        
        newClusterEntities.push(clusterEntity);
        
        // 为聚合点添加点击事件，展开显示所有点
        const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
        handler.setInputAction((click) => {
          const pickedObject = viewer.scene.pick(click.position);
          // 添加检查确保pickedObject和pickedObject.id存在
          if (pickedObject && pickedObject.id && pickedObject.id.properties && 
              pickedObject.id.properties.isCluster) {
            
            // 移除聚合点
            viewer.entities.remove(pickedObject.id);
            const index = newClusterEntities.indexOf(pickedObject.id);
            if (index > -1) {
              newClusterEntities.splice(index, 1);
            }
            
            // 添加该簇中的所有点
            // 添加检查确保properties和points存在
            if (pickedObject.id.properties && pickedObject.id.properties.points) {
              const points = pickedObject.id.properties.points.getValue();
              points.forEach(point => {
                const childEntity = viewer.entities.add({
                  position: Cesium.Cartesian3.fromDegrees(point.lon, point.lat),
                  point: {
                    pixelSize: 6,
                    color: Cesium.Color.fromRandom({alpha: 0.8}),
                    outlineColor: Cesium.Color.WHITE,
                    outlineWidth: 1
                  }
                });
                newClusterEntities.push(childEntity);
              });
            }
          }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
      });
      
      // 直接替换旧实体，不使用延迟
      this.clusterEntities.forEach(entity => {
        viewer.entities.remove(entity);
      });
      this.clusterEntities = newClusterEntities;
    }
    
    this.isUpdatingClusters = false;
  }

  // 根据地图高度确定网格大小
  getGridSizeByHeight(height) {
    if (height > 200000) {
      return 0.05; // 高空时较大网格
    } else if (height > 100000) {
      return 0.03;
    } else if (height > 50000) {
      return 0.02;
    } else {
      return 0.01; // 低空时较小网格
    }
  }

  // 添加图标点(图元)
  addBillboardPrimitive() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        // 使用Primitive方式添加图标点
        if (!this.primitiveCollection) {
          this.primitiveCollection = viewer.scene.primitives.add(new Cesium.BillboardCollection());
        }
        
        const billboard = this.primitiveCollection.add({
          position: cartesian,
          image: '/images/primitive.png',
          width: 32,
          height: 32
        });
        
        // 保存引用以便清理
        this.tempEntities.push({
          type: 'primitive',
          object: billboard
        });
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }

  // 添加线要素
  addLine() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    const positions = [];
    this.activeEntity = viewer.entities.add({
      polyline: {
        positions: new Cesium.CallbackProperty(() => {
          if (positions.length >= 2) {
            return positions;
          }
          return null;
        }, false),
        width: 3,
        material: Cesium.Color.BLUE
      }
    });
    
    this.tempEntities.push(this.activeEntity);
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        positions.push(cartesian);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
    this.drawHandler.setInputAction((click) => {
      if (positions.length < 2) {
        viewer.entities.remove(this.activeEntity);
        this.tempEntities.pop();
      } else {
        this.activeEntity.polyline.positions = positions.slice();
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
      this.activeEntity = null;
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  }

  // 添加面要素
  addPolygon() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    const positions = [];
    this.activeEntity = viewer.entities.add({
      polygon: {
        hierarchy: new Cesium.CallbackProperty(() => {
          if (positions.length >= 3) {
            return new Cesium.PolygonHierarchy(positions);
          }
          return null;
        }, false),
        material: Cesium.Color.GREEN.withAlpha(0.7)
      }
    });
    
    this.tempEntities.push(this.activeEntity);
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        positions.push(cartesian);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
    this.drawHandler.setInputAction((click) => {
      if (positions.length < 3) {
        viewer.entities.remove(this.activeEntity);
        this.tempEntities.pop();
      } else {
        this.activeEntity.polygon.hierarchy = new Cesium.PolygonHierarchy(positions.slice());
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
      this.activeEntity = null;
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  }

  // 距离测量
  measureDistance() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    const positions = [];
    this.activeEntity = viewer.entities.add({
      polyline: {
        positions: new Cesium.CallbackProperty(() => {
          if (positions.length >= 2) {
            return positions;
          }
          return null;
        }, false),
        width: 3,
        material: Cesium.Color.YELLOW
      }
    });
    
    this.tempEntities.push(this.activeEntity);
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        positions.push(cartesian);
        
        if (positions.length >= 2) {
          const distance = Cesium.Cartesian3.distance(positions[positions.length-2], positions[positions.length-1]);
          const midpoint = Cesium.Cartesian3.midpoint(positions[positions.length-2], positions[positions.length-1], new Cesium.Cartesian3());
          
          const label = viewer.entities.add({
            position: midpoint,
            label: {
              text: distance.toFixed(2) + ' m',
              font: '14px sans-serif',
              fillColor: Cesium.Color.WHITE,
              outlineColor: Cesium.Color.BLACK,
              outlineWidth: 2,
              style: Cesium.LabelStyle.FILL_AND_OUTLINE,
              pixelOffset: new Cesium.Cartesian2(0, -20)
            }
          });
          this.tempEntities.push(label);
        }
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
    this.drawHandler.setInputAction((click) => {
      if (positions.length < 2) {
        viewer.entities.remove(this.activeEntity);
        this.tempEntities.pop();
      } else {
        this.activeEntity.polyline.positions = positions.slice();
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
      this.activeEntity = null;
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  }

  // 面积测量
  measureArea() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 如果正在绘制其他内容，先取消
    if (this.drawHandler) {
      this.drawHandler.destroy();
    }
    
    const positions = [];
    this.activeEntity = viewer.entities.add({
      polygon: {
        hierarchy: new Cesium.CallbackProperty(() => {
          if (positions.length >= 3) {
            return new Cesium.PolygonHierarchy(positions);
          }
          return null;
        }, false),
        material: Cesium.Color.YELLOW.withAlpha(0.5)
      }
    });
    
    this.tempEntities.push(this.activeEntity);
    
    this.drawHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    
    this.drawHandler.setInputAction((click) => {
      const cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid);
      if (cartesian) {
        positions.push(cartesian);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
    this.drawHandler.setInputAction((click) => {
      if (positions.length < 3) {
        viewer.entities.remove(this.activeEntity);
        this.tempEntities.pop();
      } else {
        this.activeEntity.polygon.hierarchy = new Cesium.PolygonHierarchy(positions.slice());
        
        // 计算面积
        const ellipsoid = viewer.scene.globe.ellipsoid;
        let area = 0;
        if (positions.length >= 3) {
          const coordinates = positions.map(p => {
            const cartographic = ellipsoid.cartesianToCartographic(p);
            return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude)];
          });
          
          // 简单的面积计算（近似）
          area = this.calculatePolygonArea(coordinates);
        }
        
        // 添加面积标签
        if (positions.length > 0) {
          const center = positions.reduce((acc, pos) => {
            return Cesium.Cartesian3.add(acc, pos, acc);
          }, new Cesium.Cartesian3());
          Cesium.Cartesian3.divideByScalar(center, positions.length, center);
          
          const label = viewer.entities.add({
            position: center,
            label: {
              text: area.toFixed(2) + ' km²',
              font: '14px sans-serif',
              fillColor: Cesium.Color.WHITE,
              outlineColor: Cesium.Color.BLACK,
              outlineWidth: 2,
              style: Cesium.LabelStyle.FILL_AND_OUTLINE
            }
          });
          this.tempEntities.push(label);
        }
      }
      this.drawHandler.destroy();
      this.drawHandler = null;
      this.activeEntity = null;
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  }

  // 简单多边形面积计算函数
  calculatePolygonArea(coordinates) {
    // 这里使用简单的平面近似计算
    let area = 0;
    const n = coordinates.length;
    
    for (let i = 0; i < n; i++) {
      const j = (i + 1) % n;
      area += coordinates[i][0] * coordinates[j][1];
      area -= coordinates[j][0] * coordinates[i][1];
    }
    
    area = Math.abs(area) / 2.0;
    return area * 100; // 粗略转换为平方公里
  }

  // 清除所有绘制
  clearAll() {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 清除所有临时实体
    this.tempEntities.forEach(entity => {
      if (entity.type === 'primitive' && entity.object) {
        // 处理Primitive对象
        if (this.primitiveCollection) {
          this.primitiveCollection.remove(entity.object);
        }
      } else {
        viewer.entities.remove(entity);
      }
    });
    
    this.tempEntities = [];
    
    // 清除聚合点
    this.clusterEntities.forEach(entity => {
      viewer.entities.remove(entity);
    });
    this.clusterEntities = [];
    this.clusterData = [];
    this.clusterCache.clear();
    this.lastCameraHeight = null;
    
    // 清除防抖定时器
    if (this.clusterUpdateTimeout) {
      clearTimeout(this.clusterUpdateTimeout);
      this.clusterUpdateTimeout = null;
    }
    this.isUpdatingClusters = false;
    
    // 移除地图变化监听器
    if (this.clusterChangeListener) {
      viewer.camera.changed.removeEventListener(this.clusterChangeListener);
      this.clusterChangeListener = null;
    }
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    this.activeEntity = null;
    
    // 清理聚合点的定时器
    this.entityCollections.forEach((collection, key) => {
      collection.forEach(entity => {
        if (entity._animationInterval) {
          clearInterval(entity._animationInterval);
        }
      });
    });
    this.entityCollections.clear();
  }

  // 清除图层
  clearLayers() {
    this.clearAll();
    console.log('清除所有图层');
  }

  // 批量添加点相关函数
  addRandomPoints(count) {
    if (!this.cesiumManager || !this.cesiumManager.viewer) return;
    
    const viewer = this.cesiumManager.viewer;
    
    // 以长沙为中心生成随机点
    const centerLon = 112.98;
    const centerLat = 28.19;
    
    // 取消当前绘制操作
    if (this.drawHandler) {
      this.drawHandler.destroy();
      this.drawHandler = null;
    }
    
    // 批量创建点实体
    for (let i = 0; i < count; i++) {
      // 在中心点附近随机生成经纬度 (-0.1到0.1度的偏移)
      const lon = centerLon + (Math.random() - 0.5) * 0.2;
      const lat = centerLat + (Math.random() - 0.5) * 0.2;
      
      const entity = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(lon, lat),
        point: {
          pixelSize: 5,
          color: Cesium.Color.fromRandom({
            alpha: 0.7
          }),
          outlineColor: Cesium.Color.WHITE,
          outlineWidth: 1
        }
      });
      
      this.tempEntities.push(entity);
    }
    
    // 提示信息
    console.log(`成功添加 ${count} 个随机点`);
  }

  getTempEntities() {
    return this.tempEntities;
  }

  setTempEntities(entities) {
    this.tempEntities = entities;
  }
  // 绘制多边形
}